# gui/progress_bar.py - Progress bar component

from PyQt5.QtWidgets import QWidget, QVBoxLayout, QProgressBar, QLabel
from PyQt5.QtCore import Qt, pyqtSlot


class ProgressBar(QWidget):
    def __init__(self):
        super().__init__()

        # Set up the UI
        self._setup_ui()

    def _setup_ui(self):
        """Set up the progress bar UI"""
        layout = QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)

        # Status label
        self.status_label = QLabel("Ready")
        layout.addWidget(self.status_label)

        # Progress bar
        self.progress_bar = QProgressBar()
        self.progress_bar.setRange(0, 100)
        self.progress_bar.setValue(0)
        layout.addWidget(self.progress_bar)

        self.setLayout(layout)

    @pyqtSlot(int, str)
    def set_progress(self, value, status=None):
        """Update the progress bar value and status"""
        self.progress_bar.setValue(value)

        if status:
            self.status_label.setText(status)
        else:
            # Auto-generate status based on progress
            if value == 0:
                self.status_label.setText("Ready")
            elif value == 100:
                self.status_label.setText("Completed")
            else:
                self.status_label.setText(f"Processing: {value}%")

    def reset(self):
        """Reset the progress bar to initial state"""
        self.progress_bar.setValue(0)
        self.status_label.setText("Ready")